import request from './request'

// 授权管理API
export const authApi = {
  // 为用户分配角色
  assignRolesToUser(data) {
    return request({
      url: '/auth/user-roles',
      method: 'post',
      data
    })
  },

  // 为角色分配权限
  assignPermissionsToRole(data) {
    return request({
      url: '/auth/role-permissions',
      method: 'post',
      data
    })
  },

  // 获取用户权限预览
  getUserPermissionPreview(userId) {
    return request({
      url: `/auth/user/${userId}/preview`,
      method: 'get'
    })
  },

  // 获取角色权限预览
  getRolePermissionPreview(roleId) {
    return request({
      url: `/auth/role/${roleId}/preview`,
      method: 'get'
    })
  },

  // 检查用户是否有指定权限
  hasPermission(userId, permissionCode) {
    return request({
      url: '/auth/check-permission',
      method: 'get',
      params: { userId, permissionCode }
    })
  },

  // 检查用户是否有指定资源和操作的权限
  hasResourcePermission(userId, resource, action) {
    return request({
      url: '/auth/check-resource',
      method: 'get',
      params: { userId, resource, action }
    })
  },

  // 获取用户的所有权限编码
  getUserPermissionCodes(userId) {
    return request({
      url: `/auth/user/${userId}/permission-codes`,
      method: 'get'
    })
  },

  // 获取用户的菜单权限
  getUserMenuPermissions(userId) {
    return request({
      url: `/auth/user/${userId}/menu-permissions`,
      method: 'get'
    })
  },

  // 获取用户的操作权限
  getUserOperationPermissions(userId) {
    return request({
      url: `/auth/user/${userId}/operation-permissions`,
      method: 'get'
    })
  }
}
